<template>
  <div>
    <button-tab class="button-tab-class">
      <button-tab-item @click.native="getDis" selected>发布的讨论</button-tab-item>
      <button-tab-item @click.native="getComment">收到的评论</span>
      </button-tab-item>
      </button-tab-item>
    </button-tab>
    <panel v-if="disShow" :list="discussions" type="1"></panel>
    <panel v-if="comentShow" :list="comments" type="2"></panel>
  </div>
  </div>
</template>

<script>
  import { ButtonTab, ButtonTabItem, Panel } from 'vux'
  import { getToken } from "@/utils/auth"
  import { getDiscussion, getUserComment } from "@/api/user"
  export default {
    components: {
      ButtonTab, ButtonTabItem, Panel
    },
    data() {
      return {
        token: "",
        discussions: [],
        comments: [],
        disShow: true,
        comentShow: false
      }

    },
    created() {
      this.token = getToken()
      this.getDis()
    },
    methods: {
      getDis() {
        this.disShow = true
        let token = this.token
         this.comentShow = false
        getDiscussion(token).then((res) => {
          if (res.message == "ok") {
            this.discussions = res.discussion.map((item) => {
              item.src = item.avatar
              item.title = item.user
              item.desc = item.text
              item.url = "/discussion/detail?id=" + item.id
              return item
            })
          }
        })
      },
      getComment() {
        this.disShow = false
        this.comentShow = true
        let token = this.token
        getUserComment(token).then((res) => {
          if (res.message == "ok") {
            this.comments = res.comments.map((item) => {
              item.src = item.avatar
              item.title = item.username+"评论我："
              item.desc = item.text
              item.url = "/discussion/detail?id=" + item.dis_id
              return item
            })
          }
        })
      }
    }
  }

</script>

<style>

</style>